package com.hopu.oa.dao.file;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hopu.oa.entity.file.FileList;
import com.hopu.oa.entity.file.FilePath;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author Secret
 * @create 2021-07-26 下午 03:27
 */
@Mapper
@Repository
public interface FilePathDao extends BaseMapper<FilePath> {
    @Select("select * from aoa_file_path where path_name=#{filename} ")
    FilePath findByPathName(String pathname);


    @Select("select * from aoa_file_path where parent_id=#{id} and path_istrash=0 ")
    List<FilePath> findPathByParentId(int id);

    @Select("select * from aoa_file_list fl join aoa_file_path fp on fl.path_id=fp.path_id where fp.path_user_id=#{id} and fl.file_istrash=0 and fp.path_id = 6")
    List<FileList> findFileList(int id);

    @Select("select * from aoa_file_path where path_id=#{parentId}")
    FilePath findAllParent(int parentId);

    @Select("select * from aoa_file_path where path_id=#{pathId}")
    FilePath findOnePath(int pathId);


    int moveFilePathByBatch(@Param("mcpathids") String mcpathids, @Param("mctoid") Integer mctoid, @Param("userId") Integer userId);


    //ajax的Controller数据查询
    @Select("select * from aoa_file_list  where file_user_id=#{userId} and file_istrash=0 and content_type not like 'image' and content_type NOT LIKE 'application' and content_type NOT LIKE 'video' and content_type NOT LIKE 'audio' and file_name like concat ('%',#{findfileandpath},'%')")
    List<FileList> finddocument(int userId, String findfileandpath);

    @Select("select * from aoa_file_list  where file_user_id=#{userId} and content_type like concat ('%',#{contenttype},'%') and file_istrash=0 and file_name like concat ('%',#{findfileandpath},'%')")
    List<FileList> findfilecontent(int userId, String contenttype, String findfileandpath);

    @Select("select * from aoa_file_path where path_user_id=#{userId} and path_istrash=1 and path_name like concat ('%',#{findfileandpath},'%')")
    List<FilePath> findByPathUserIdAndPathIstrash(int userId, String findfileandpath);

    @Select("select * from aoa_file_list where file_user_id=#{userId} and file_istrash=1 and file_name like concat ('%',#{findfileandpath},'%')")
    List<FileList> findByFileUserIdAndPathIstrash(int userId, String findfileandpath);


    @Select("select * from aoa_file_list where file_isshare=1 and file_istrash=0 and file_name like concat ('%',#{findfileandpath},'%') ")
    List<FileList> findByFileIsshareAndFileIstrash(String findfileandpath);

    @Select("select * from aoa_file_path where path_user_id=#{userId} and path_istrash=0 and path_name like concat ('%',#{findfileandpath},'%')")
    List<FilePath> findByUserIdAndPathIstrash(int userId, String findfileandpath);

    @Select("select * from aoa_file_list where file_user_id=#{userId} and file_istrash=0 and file_name like concat ('%',#{findfileandpath},'%')")
    List<FileList> findByUserIdAndFileIsTrash(int userId, String findfileandpath);


    //Service里面查询数据
    @Select("select * from aoa_file_path where parent_id=#{parentId} and path_istrash=0 ")
    List<FilePath> findByParentIdAndPathIstrash(int parentId);

    @Select("select * from aoa_file_list where path_id=#{pathId} and file_istrash=0")
    List<FileList> findByFpathAndFileIstrash(int pathId);


    //还原
    @Select("select * from aoa_file_path where parent_id=#{parentId} and path_user_id=#{userId}")
    FilePath findByParentIdAndPathUserId(int parentId, int userId);


}
